﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class PagerHelper
    {
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="tableName">数据表名称</param>
        /// <param name="fields">要获取的字段（各字段用逗号分隔）</param>
        /// <param name="orderField">排序所根据的字段</param>
        /// <param name="pageSize">每页显示的记录数</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="condition">筛选条件（不要加where）</param>
        /// <returns></returns>
        public static SqlDataReader GetPagerData(string tableName, string fields, string orderField, int pageSize, int pageIndex, string condition)
        {
            SqlDataReader data = SqlHelper.ExecuteReader(System.Data.CommandType.StoredProcedure, "CommonPager",
                 new SqlParameter("@tblName", tableName),
                 new SqlParameter("@strGetFields", fields),
                 new SqlParameter("@fldName", orderField),
                 new SqlParameter("@PageSize", pageSize),
                 new SqlParameter("@PageIndex", pageIndex),
                 new SqlParameter("@doCount", 0),
                 new SqlParameter("@OrderType", 1),
                 new SqlParameter("@strWhere", condition));

            return data;
        }
    }
}
